package cn.micai.base.asyn;

/**
 * 描述：Java 1.0的通过Thread 类 和 Runnable接口

 Thread类实现了Runnable接口。

 一般用法：

 1）创建一个类SendToCUPD，实现Runnable接口，重写run()方法去实现任务

 2）创建一个类SendToCUPD的实例， 作为参数去新建一个Thread并调用Thread.start 方法。 然后系统去新建一个线程去执行这个任务
 * <p>
 *
 * @author: 赵新国
 * @date: 2018/5/25 15:18
 */
public class JThread {

    public static void main(String [] args) {
        System.out.println("get request from TC thread id="+Thread.currentThread().getId());

        Runnable createRM = new CreateRichMedia("Thread RM");
        new Thread(createRM).start();

        Runnable tCUPD = new SendToCUPD("Thread CUPD");
        new Thread(tCUPD).start();

        System.out.println("End main method");

    }

    static class SendToCUPD implements Runnable {
        public String name;
        public SendToCUPD(String name) {
            this.name = name;
        }
        @Override
        public void run() {
            System.out.println("b4 send to cupd");
            try {
                System.out.println("sending to cupd, thread id="+Thread.currentThread().getId());
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("end send to cupd");
        }
    }

    static class CreateRichMedia implements Runnable {
        public String name;
        public CreateRichMedia(String name) {
            this.name = name;
        }
        @Override
        public void run() {
            System.out.println("start response Rich media");
            try {
                System.out.println("creating response Rich media, thread id="+Thread.currentThread().getId());
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("End response Rich media");
        }
    }


}
